using Grpc.Core;
using Identity.Application.Contracts.Services;
using PermissionCenter.Grpc;

namespace Identity.HttpAPI.GrpcServices;

public class PermissionCenterGrpcService : PermissionCenter.Grpc.PermissionCenter.PermissionCenterBase
{
    private readonly IPermissionCenterService _permissionService;

    public PermissionCenterGrpcService(IPermissionCenterService permissionService)
    {
        _permissionService = permissionService;
    }

    public override async Task<UserPermissionReply> UserHasPermission(UserPermissionRequest request, ServerCallContext context)
    {
        // 调用应用层的权限验证逻辑
        var hasPermission = await _permissionService.UserHasPermissionAsync(request.UserId, request.PermissionKey);

        return new UserPermissionReply
        {
            HasPermission = hasPermission
        };
    }
}